/*
 * x86_64/ints.hh - Interrupts-related data types and functions.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_X86_64_INTS_HH
#define HEADER_X86_64_INTS_HH

#include HEADER (x86_64,regs.hh)

START_NAMESPACE (x86_64)

static const u8_t INT_DE = 0;
static const u8_t INT_DB = 1;
static const u8_t INT_NMI = 2;
static const u8_t INT_BP = 3;
static const u8_t INT_OF = 4;
static const u8_t INT_BR = 5;
static const u8_t INT_UD = 6;
static const u8_t INT_NM = 7;
static const u8_t INT_DF = 8;
static const u8_t INT_TS = 10;
static const u8_t INT_NP = 11;
static const u8_t INT_SS = 12;
static const u8_t INT_GP = 13;
static const u8_t INT_PF = 14;
static const u8_t INT_MF = 16;
static const u8_t INT_AC = 17;
static const u8_t INT_MC = 18;
static const u8_t INT_XF = 19;

union int_sec_t
{
  struct
    {
      u32_t EXT : 1;
      u32_t IDT : 1;
      u32_t TI : 1;
      u32_t index : 13;
      u32_t : 16;
    };
  u32_t raw;
};

union int_pfec_t
{
  struct
    {
      u32_t P : 1;
      u32_t RW : 1;
      u32_t US : 1;
      u32_t RSV : 1;
      u32_t ID : 1;
      u32_t : 27;
    };
  u32_t raw;
};

struct int_frame_t
{
  union
    {
      int_sec_t sec;
      int_pfec_t pfec;
    };
  u64_t rip;
  u16_t cs;
  flags_t flags;
  u64_t rsp;
  u16_t ss;
};

INLINE
static void
halt ()
{
  asm volatile (
    "hlt\n"
  );
}

INLINE
static void
disable_ints ()
{
  asm volatile (
    "cli\n"
  );
}

INLINE
static void
enable_ints ()
{
  asm volatile (
    "sti\n"
  );
}

END_NAMESPACE

#endif /* HEADER_X86_64_INTS_HH */

